<?php
namespace app\index\model;
use think\Model;
use think\Db;
use think\Cache;

class Nav extends Model
{
	public function getOneData( $id )
	{
		return self::field('nav_id,nav_name,nav_icon,nav_price,original_price')
					->where('nav_id', $id)
					->where('is_show', 1)
					->find();
	}

	public function getAllData( $param = [] )
	{
		return self::field('nav_id,nav_name,nav_price,nav_icon,nav_back')
					->when($param['nav_id'], function($query)use ($param){
						$query->where('nav_id', 'in', $param['nav_id']);
					})
					->where('is_show', 1)
					->order('nav_sort desc')
					->select();
	}

	public function getAllDataIds($param = [], $field = 'nav_id' )
	{
		return self::where('is_show', 1)
					->when($param['nav_id'], function($query)use ($param){
						$navIds = implode(',', $param['nav_id']);
						$query->where('nav_id', 'in', $param['nav_id'])
								->order('field(nav_id,'.$navIds.')');
					})
					->column($field);
	}
}